﻿<phone:PhoneApplicationPage 
    x:Class="Locima.SlidingBlock.GamePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModel="clr-namespace:Locima.SlidingBlock.ViewModel"
    xmlns:controls="clr-namespace:Locima.SlidingBlock.Controls"
    xmlns:converters="clr-namespace:Locima.SlidingBlock.Converters"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True"
    Style="{StaticResource TransitionPageStyle}">

    <phone:PhoneApplicationPage.Resources>
        <converters:ElapsedTimeConverter x:Key="ElapsedTimeConverter" />
        <viewModel:PuzzleViewModel x:Key="ViewModel"/>
        <Style TargetType="Border" x:Key="AreaBorder">
            <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
            <Setter Property="BorderThickness" Value="3"/>
        </Style>
    </phone:PhoneApplicationPage.Resources>


    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent" ShowGridLines="False" SizeChanged="LayoutRootSizeChanged"
          DataContext="{Binding Source={StaticResource ViewModel}}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" 
                       Text="{Binding Path=Strings.ApplicationName, Source={StaticResource Localization}}"
                       Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="{Binding PageTitle}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <Grid x:Name="GameMetadataPanel" Grid.Row="1" Margin="0,0,12,12" HorizontalAlignment="Right" Width="468">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            
            <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" Margin="12,0,12,12">
                <TextBlock Text="{Binding Path=Strings.MovesLabel, Source={StaticResource Localization}}" Margin="0,0,12,0"/>
                <TextBlock Text="{Binding MoveCount}"/>
            </StackPanel>
            
            <StackPanel Grid.Row="0" Grid.Column="2" Orientation="Horizontal">
                <TextBlock Text="{Binding Path=Strings.TimeLabel,Source={StaticResource Localization}}" Margin="0,0,12,0"/>
                <TextBlock Text="{Binding Path=ElapsedTime, Converter={StaticResource ElapsedTimeConverter}, ConverterParameter='hh\\:mm\\:ss'}"/>
            </StackPanel>
        </Grid>

        <Border Grid.Column="0" Grid.Row="2" Style="{StaticResource AreaBorder}" x:Name="PuzzleBorder" VerticalAlignment="Center" HorizontalAlignment="Center">
            <controls:Puzzle x:Name="Puzzle" Margin="12,12,12,12" 
                             GameState="{Binding Path=GameState,Source={StaticResource ViewModel},Mode=OneWay}">
                <controls:Puzzle.PauseScreen>
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <Rectangle Fill="{StaticResource PhoneAccentBrush}"/>
                        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" 
                           Text="{Binding Path=Strings.PausedMessage, Source={StaticResource Localization}}" 
                           Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                    </Grid>
                </controls:Puzzle.PauseScreen>
                <controls:Puzzle.StartScreen>
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <Rectangle Fill="{StaticResource PhoneBackgroundBrush}" Opacity="0.5"/>
                        <StackPanel VerticalAlignment="Center">
                            <StackPanel.Resources>
                                <Style TargetType="HyperlinkButton" x:Name="Hyperlink">
                                    <Setter Property="Foreground" Value="{StaticResource PhoneSubtleBrush}"/>
                                    <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeSmall}"/>
                                </Style>
                            </StackPanel.Resources>
                            <Button Tap="ImageLinkTap"
                                    Content="{Binding ImageTitle}"
                                    Margin="0,12,0,0"
                            />
                            <TextBlock Text="{Binding ImageText}" TextAlignment="Center"
                                   Margin="0,12,0,0" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap"/>
                            <TextBlock Text="{Binding Path=Strings.LevelByLabel,Source={StaticResource Localization}}" TextAlignment="Center"
                                   Margin="0,12,0,0" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap"/>
                            <TextBlock Text="{Binding Path=ImageOwner}" TextAlignment="Center"
                                   Margin="0,12,0,0" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap"/>
                            <Button Tap="LicenseLinkTap"
                                    Content="{Binding LicenseTitle}"
                                    Margin="0,12,0,0"
                            />
                            <TextBlock Text="{Binding Path=Strings.StartLevelPrompt, Source={StaticResource Localization}}" HorizontalAlignment="Center" Style="{StaticResource PhoneTextExtraLargeStyle}" Margin="0,24,0,0" />
                        </StackPanel>
                    </Grid>
                </controls:Puzzle.StartScreen>
                <controls:Puzzle.CompleteScreen>
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <Rectangle Fill="{StaticResource PhoneBackgroundBrush}" Opacity="0.5"/>
                        <StackPanel VerticalAlignment="Center">
                            <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding CompletedTitle}" TextAlignment="Center"
                                   Margin="0,0,0,0" Style="{StaticResource PhoneTextLargeStyle}" TextWrapping="Wrap"/>
                            <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding CompletedText}" TextAlignment="Center"
                                   Margin="0,12,0,0" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap"/>
                            <TextBlock Text="{Binding Path=Strings.StartNextLevelPrompt, Source={StaticResource Localization}}" HorizontalAlignment="Center" Style="{StaticResource PhoneTextExtraLargeStyle}"
                                   Margin="0,24,0,0" />
                        </StackPanel>
                    </Grid>
                </controls:Puzzle.CompleteScreen>
            </controls:Puzzle>
        </Border>

    </Grid>

</phone:PhoneApplicationPage>

    